package com.xux.enums;

import java.util.Arrays;

/**
 * 操作类型.
 *
 * @author xux
 */
public enum OperateTypes {

    INSERT, UPDATE, DELETE;

    /**
     * 获取枚举值.
     * @param type 枚举类型
     * @return 枚举值
     */
    public static OperateTypes fromType(final String type) {
        for (OperateTypes types : OperateTypes.values()) {
            if (types.name().equalsIgnoreCase(type)) {
                return types;
            }
        }
        return null;
    }

    /**
     * 获取枚举值.
     * @param type 枚举类型
     * @return 枚举值
     */
    public static boolean checkType(final String type) {
        return Arrays.stream(OperateTypes.values()).anyMatch(t -> t.name().equalsIgnoreCase(type));
    }
}
